//
//  LOLSquadViewController.m
//  LOLXXbox
//
//  Created by dllo on 16/1/28.
//  Copyright © 2016年 Grasstrio. All rights reserved.
//

#import "LOLSquadViewController.h"
#import "LOLSquadTableViewCell.h"
#import <AFNetworking.h>
#import "LSZNetWorkTools.h"
#import "LOLSquadModel.h"
@interface LOLSquadViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *dataSource;
@property (nonatomic, strong) NSArray *heroArray;
@property (nonatomic, strong) LOLSquadModel *model;

@end

@implementation LOLSquadViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"最佳阵容";
    self.view.backgroundColor = [UIColor whiteColor];
    [self creatTableView];
    [self getData];
}

- (void)creatTableView{
    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    [self.tableView registerClass:[LOLSquadTableViewCell class] forCellReuseIdentifier:@"cell"];
    [self.view addSubview:self.tableView];
    self.dataSource = [NSMutableArray array];
    self.heroArray = [NSArray array];
 
}

- (void)getData{
    [LSZNetWorkTools getWithUrl:@"http://box.dwstatic.com/apiHeroBestGroup.php" parameter:nil httpHeader:nil resposeType:ResponseTypeJSON success:^(id result) {
        NSArray *array = result;
        for (NSDictionary *dic in array) {
            self.model = [[LOLSquadModel alloc] initWithDataSource:dic];
            [self.dataSource addObject:_model];
//             self.heroArray = @[_model.hero1, _model.hero2, _model.hero3, _model.hero4, _model.hero5];
//            NSLog(@"----------%@", self.heroArray);
//            NSLog(@"+++++%@",self.dataSource);
            
        }
        [_tableView reloadData];
    } fail:^(NSError *error) {
        
    }];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    LOLSquadTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    cell.squadModel = self.dataSource[indexPath.row];
//    NSLog(@"%@",self.dataSource);

    self.model = self.dataSource[indexPath.row];
    self.heroArray = @[_model.hero1, _model.hero2, _model.hero3, _model.hero4, _model.hero5];
    cell.nameArray = self.heroArray;

//    NSLog(@"----------%@", self.heroArray);
   
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return CGFLOAT_MIN;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 64;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 200;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
